<template>
  <div class="right-top" ref="target"></div>
</template>

<script setup>
import { onMounted, ref, defineProps, watch } from "vue";
import * as echarts from "echarts";
const props = defineProps({
  dataReconfiguration: {
    type: Array,
    required: true,
  },
  rouMin: {
    type: Number,
  },
});

const target = ref(null);
let mChart = null;
onMounted(() => {
  mChart = echarts.init(target.value);
  renderChart();
});
const renderChart = () => {
  const bgImg = new URL(`../../assets/imgs/1.jpeg`, import.meta.url);
  let options = {
    backgroundColor: "#081736",

    title: {
      text: "电压曲线数据集的ρ-δ分布图",

      textStyle: {
        color: "white",
      },
    },
    grid: {
      left: 50,
      top: 50,
      bottom: 50,
      right: 26,
    },
    xAxis: {
      axisLabel: {
        color: "white",
      },
      name: "局部密度ρ",
      nameLocation: "center",
      nameTextStyle: {
        padding: [10, 0, 0, 0],
        color: "white",
      },
      min: props.rouMin,
    },
    yAxis: {
      axisLabel: {
        color: "white",
      },
      name: "相对距离δ",
      nameLocation: "center",
      nameTextStyle: {
        padding: [0, 0, 10, 0],
        color: "white",
      },
      // min: props.rouMin,
    },
    series: [
      {
        symbolSize: 16,
        data: props.dataReconfiguration,
        type: "scatter",
        itemStyle: {
          //点的颜色
          color: (params) => {
            console.log(params.value[1]);
            if (params.value[1] > 1.1) {
              return "#80FFA5";
            } else {
              return "rgb(159, 236, 77)";
            }
          },
        },
      },
    ],
  };
  mChart.setOption(options);
};
window.addEventListener("resize", function () {
  mChart.resize();
});
watch(
  () => props.dataReconfiguration,
  () => {
    renderChart();
  }
);
</script>

<style lang="scss" scoped>
.right-top {
  width: 95%;
  height: 95%;
  padding: 10px;
}
</style>
